package lumis.service.portalmanagement.audit;

import lumis.doui.source.IDataProvider;
import lumis.doui.source.ISourceData;
import lumis.doui.source.TabularData;
import lumis.doui.source.TabularSource;
import lumis.portal.PortalException;
import lumis.portal.audit.AuditConfig;
import lumis.portal.audit.AuditManager;
import lumis.portal.authentication.SessionConfig;
import lumis.portal.manager.ManagerFactoryInternal;
import lumis.util.ITransaction;

/**
 * Data provider for Audit configuration.
 *
 * @version $Revision: 13092 $ $Date: 2011-05-28 18:19:06 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class AuditConfigDataProvider implements IDataProvider<TabularSource<?>>
{
	public void loadData(SessionConfig sessionConfig, TabularSource<?> source, ITransaction transaction) throws PortalException
	{
		AuditConfig auditConfig = obtainAuditConfig();
		fillTabularData(source, auditConfig);
	}
	
	/**
	 * Obtain audit configuration data.
	 * @return	an instance of {@link lumis.portal.audit.AuditConfig}
	 * 			representing the audit configuration in database.
	 * @throws PortalException	if an error occur retrieving the configuration.
	 * @since 6.0.0
	 */
	private AuditConfig obtainAuditConfig() throws PortalException
	{
		AuditManager auditManager = (AuditManager) ManagerFactoryInternal.getAuditManager();
		return auditManager.obtainConfiguration();
	}
	
	/**
	 * Fill the tabular data with the audit configuration data.
	 * @param source			the instance of {@link lumis.doui.source.TabularSource}.
	 * @param auditConfig		the instance of {@link lumis.portal.audit.AuditConfig}.
	 * @throws PortalException	if an error occur filling the tabular data.
	 * @since 6.0.0
	 */
	protected void fillTabularData(TabularSource<?> source, AuditConfig auditConfig) throws PortalException 
	{	
		TabularData tabularData = source.getData();		
		ISourceData row = tabularData.addRow();
		row.put("cleanInterval", auditConfig.getCleanInterval());		
	}
}